package com.bignerdranch.android.technew;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class RecyclerActivity extends AppCompatActivity {

    private RecyclerView recycler;
    private List<Bean> mBeanList;
    private onItemClicked mItemClicked;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler);
        initView();
    }

    private void initView() {
        recycler = (RecyclerView) findViewById(R.id.recycler);
        initData();
        mItemClicked = new onItemClicked() {
            @Override
            public void onClicked(View view ,int position) {
                Toast.makeText(getApplicationContext(),position+" onClicked",Toast.LENGTH_SHORT).show();
            }
        };
//        recycler.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,true));
        recycler.setLayoutManager(new GridLayoutManager(this,5,LinearLayoutManager.VERTICAL,false));
//        recycler.setLayoutManager(new StaggeredGridLayoutManager(5,StaggeredGridLayoutManager.HORIZONTAL));
        recycler.setAdapter(new MyAdapter(mBeanList,this,mItemClicked));

    }

    private void initData(){
        mBeanList = new ArrayList<>();
        for(int i = 0;i <100 ;i++){
            Bean bean = new Bean("item"+i);
            mBeanList.add(bean);
        }
    }
}
